"""
@ -*- coding: utf-8 -*-
@ IDE: PyCharm
@ Author: 陈雄伟
@ DateTime: 2022/7/7 15:03 
@ FileName: pythonProject2 
@ ProjectName:回合制对战游戏
"""


class Role:

    def __init__(self, name, sex, blood, equip):
        self.name = name
        self.sex = sex
        self.blood = blood
        self.equip = equip


    def battle(self, a, b):
      pass


class Room:

    def __init__(self,name):
        self.name = name
        self.num = 2

    def add_room(self):
        pass



if __name__ == '__main__':
    role_dic = {}   # 存放总共的角色
    room_list = []  # 存放总共的房间
    battle_role = [] # 开始对战时的角色， 最多两个
    battle_room = {}  # 游戏开始时对战的房间
    while True:
        print('*'*20)
        print('1.创建房间')
        print('2.创建角色')
        print('3.加入房间')
        print('4.开始对战')
        print('5.退出')
        print('*'*20)
        choose = input('请输入你选择的项：')
        if choose == '1':
            room_name = input('请输入房间名：')
            room = Room(room_name)
            if room_name not in room_list:
                room_list.append(room_name)
                print(f'房间人数上限:{room.num}')

        elif choose == '2':
            name, sex, blood, equip = (input('请依次输入角色名、性别、血量、装备(以空格分开)：').split(" "))
            role = Role(name, sex, blood, equip)
            if name not in role_dic:
                role_dic[name] = {'sex': sex, 'blood': blood, "equip": equip}
                #print(role_dic)
            else:
                print('角色已存在！！')

        elif choose == '3': # 加入房间
            if len(room_list) != 0:
                print("可用的房间有:",end=' ')
                for i in room_list:
                    print(i,end=' ')
                print()
            else:
                print('暂无房间！请先创建房间')
                continue
            room = input('请选择房间:')
            if room in room_list:
                print(f'选择{room}号房间成功')
            else:
                print(f'房间名错误，选择房间失败！！')
            print('请选择对战角色！！')
            if len(role_dic.items()) < 2:
                print('角色不足，请先创建角色')
                continue
            else:
                print('可用的角色有：',end=' ')
                for key in role_dic:
                    print(key, end=" ")
            print()
            try:
                role1, role2 = input('请选择角色1和角色2(只能选择两个角色，空格分开)：').split(" ")
                if role1 in role_dic and role2 in role_dic:
                    battle_room[role1] = role_dic[role1]
                    battle_room[role2] = role_dic[role2]
                    battle_role.append(role1)
                    battle_role.append(role2)
                    print('角色选择成功！！,请选择开始对战')

                else:
                    print('角色选择错误，请重新输入！！')

            except Exception as e:
                print('最多只能两个角色同时进行对战游戏！')


        elif choose == '4':  # 开始对战

       
            while True:

                print('开始对战！！')
                for role in battle_role:
                    print(role,end='    ')
                print('\n技能列表')
                print('A:青莲剑歌,伤害20%')
                print('B:河豚飞弹,伤害10%')
                print('C:炽热光辉,伤害30%')
                skill_dic = {'A':'青莲剑歌', 'B':'河豚飞弹', 'C':'炽热光辉'}
                print(f'\n1.{battle_role[0]}攻击{battle_role[1]}')
                print(f'2.{battle_role[1]}攻击{battle_role[0]}')
                print('3.退出')

                ch = input(('请选择攻击方式：'))
                if ch == '1':
                    skill = input('请选择攻击技能：')
                    if skill == 'A':
                        if battle_room[battle_role[1]]['equip'] == '1':
                            battle_room[battle_role[1]]['blood'] = int(battle_room[battle_role[1]]['blood'])-10
                        else:
                            battle_room[battle_role[1]]['blood'] = int(battle_room[battle_role[1]]['blood']) - 20
                    if skill == 'B':
                        if battle_room[battle_role[1]]['equip'] == '1':
                            battle_room[battle_role[1]]['blood'] = int(battle_room[battle_role[1]]['blood'])-5
                        else:
                            battle_room[battle_role[1]]['blood'] = int(battle_room[battle_role[1]]['blood']) - 10
                    if skill == 'C':
                        if battle_room[battle_role[1]]['equip'] == '1':
                            battle_room[battle_role[1]]['blood'] = int(battle_room[battle_role[1]]['blood'])-15
                        else:
                            battle_room[battle_role[1]]['blood'] = int(battle_room[battle_role[1]]['blood']) - 30

                    print(f'{battle_role[0]}使用技能{skill_dic[skill]}攻击了{battle_role[1]}')
                    print(f'{battle_role[1]}的血量为{battle_room[battle_role[1]]["blood"]}')
                    if battle_room[battle_role[1]]["blood"] <= 0:
                        print(f'{battle_role[0]}赢得了胜利！')
                        break
                elif ch == '2':
                    skill = input('请选择攻击技能：')
                    if skill == 'A':
                        if battle_room[battle_role[0]]['equip'] == '1':
                            battle_room[battle_role[0]]['blood'] = int(battle_room[battle_role[0]]['blood']) - 10
                        else:
                            battle_room[battle_role[0]]['blood'] = int(battle_room[battle_role[0]]['blood']) - 20
                    if skill == 'B':
                        if battle_room[battle_role[0]]['equip'] == '1':
                            battle_room[battle_role[0]]['blood'] = int(battle_room[battle_role[0]]['blood']) - 5
                        else:
                            battle_room[battle_role[0]]['blood'] = int(battle_room[battle_role[0]]['blood']) - 10
                    if skill == 'C':
                        if battle_room[battle_role[0]]['equip'] == '1':
                            battle_room[battle_role[0]]['blood'] = int(battle_room[battle_role[0]]['blood']) - 15
                        else:
                            battle_room[battle_role[0]]['blood'] = int(battle_room[battle_role[0]]['blood']) - 30

                    print(f'{battle_role[1]}使用技能{skill_dic[skill]}攻击了{battle_role[0]}')
                    print(f'{battle_role[0]}的血量为{battle_room[battle_role[0]]["blood"]}')
                    if battle_room[battle_role[1]]["blood"] <= 0:
                        print(f'{battle_role[0]}赢得了胜利！')
                        break
                elif ch == '3':
                    break
                else:
                    print('输入错误！，请重新输入！')
                    continue


        elif choose == '5': # 退出

            break
        else:
            print('输入错误，请重新输入！！')

